<?php
namespace Admin\Controller;
use Common\Controller\AdminbaseController;
class LivePushOperatorController extends AdminbaseController {
	
	private $live_push_operator;
	
	function _initialize() {
		parent::_initialize();
		$this->live_push_operator = D("Common/LivePushOperator");
	}
	
	function index(){
		$status = I("post.status", -1);
		$name = I("post.name", "");
		$mobile_phone = I("post.mobile_phone", "");
		$count = $this->live_push_operator->queryLivePushOperatorCount($status, $name, $mobile_phone);
		$page = $this->page($count, 20);
		
		$result = $this->live_push_operator->queryLivePushOperatorList($status, $name, $mobile_phone, $page->firstRow , $page->listRows);
		
		$this->assign("data", $result);
		$this->assign("formParam", array('status'=>$status,'name'=>$name,'mobile_phone'=>$mobile_phone));
		$this->assign("page", $page->show('Admin'));
		$this->display();
	}
	
	function add(){
		$this->display();
	}
	
	function add_post(){
		if(IS_POST){
			$_POST['creator_id'] = $_SESSION["ADMIN_ID"];
			if($_POST['password'] && !empty($_POST['password'])){
				if(strlen($_POST['password']) < 6){
					$this->error('密码必须为6个字符以上！');
					return;
				}
				$_POST['password'] = md5(md5($_POST['password']));
			}
			if ($this->live_push_operator->create()) {
				$result = $this->live_push_operator->add();
				if ($result!==false) {
					$this->success("添加成功！", U("Admin/LivePushOperator/index"));
				} else {
					$this->error("添加失败！");
				}
			} else {
				$this->error($this->live_push_operator->getError());
			}
			
		}
	}
	
	function edit_real_name(){
		$operator_id = I("post.operator_id", 0);
		$real_name = I("post.real_name", "");
		
		$result = $this->live_push_operator->where(array('operator_id'=>$operator_id))->save(array('real_name'=>$real_name));
		if($result){
			$this->success("修改成功！", U("Admin/LivePushOperator/index"));
		}else{
			return $this->error("修改失败！");
		}
	}
	
	function reset_pwd(){
		$operator_id = I("post.operator_id", 0);
		$password = I("post.password", 0);
		
		$result = $this->live_push_operator->where(array('operator_id'=>$operator_id))->save(array('password'=>md5(md5($password))));
		if($result){
			$this->success("修改成功！", U("Admin/LivePushOperator/index"));
		}else{
			return $this->error("修改失败！");
		}
	}
	
	function disable(){
		$operator_id = I("get.operator_id", 0);
		$status = 0;
		$postData = array(
			'status'=>$status
		);
		$result = $this->live_push_operator->where(array('operator_id'=>$operator_id))->save($postData);
		if($result){
			$this->success("禁用成功！", U("Admin/LivePushOperator/index"));
		}else{
			return $this->error("禁用失败！");
		}
	}
	
	function enable(){
		$operator_id = I("get.operator_id", 0);
		$status = 1;
		$postData = array(
			'status'=>$status
		);
		$result = $this->live_push_operator->where(array('operator_id'=>$operator_id))->save($postData);
		if($result){
			$this->success("启用成功！", U("Admin/LivePushOperator/index"));
		}else{
			return $this->error("启用失败！");
		}
	}
	
	function delete(){
		$operator_id = I("get.operator_id", 0);
		$status = 2;
		$postData = array(
				'status'=>$status
		);
		$result = $this->live_push_operator->where(array('operator_id'=>$operator_id))->save($postData);
		if($result){
			$this->success("删除成功！", U("Admin/LivePushOperator/index"));
		}else{
			return $this->error("删除失败！");
		}
	}
}